//index.js
//获取应用实例
const app = getApp()

Page({
	data: {
		input_true: false,
		input_on: ' ',
		input_words: ' ',
		words: ' ',
		input_height: '',

	},
	onReady: function() {
		app.SystemInfo(this)
	},
	input_click: function() {
		this.setData({
			input_true: true,
		})
	},
	watchPassWord: function(event) {
		this.setData({
			input_on: 'on'
		});
	},
	input_off: function() {
		this.setData({
			input_on: ' '
		});
	},
	input_wrds: function() {
		this.setData({
			input_words: 'on'
		});
	},
	input_out: function() {
		this.setData({
			input_words: ' '
		});
	},
	onLoad: function(options) {
		var comm_id = options.id;
		var that = this;
		app.request(app.apiDomain + "index.php?c=health&a=detail", {
			id : options.id
		}, function(res) {
			that.setData({
				news_detail: res.data.data,
			});
			wx.setNavigationBarTitle({
				title: res.data.data.f_title,
			})
			var WxParse = require('../../wxParse/wxParse.js');
			wx.setStorageSync('title', res.data.data.f_title);
			var article = res.data.data.f_content;
			WxParse.wxParse('article', 'html', article, that, 0);
		});
		app.request(app.apiDomain + "index.php?c=health&a=comments", {
			id : options.id
		}, function(res) {
			that.setData({
				common_list: res.data.data.list,
				common_total: res.data.data.total
			});
		});
	},
	formSubmit: function(e) {
		var nickName = '';
		var avatarUrl = '';
		try {
			nickName = wx.getStorageSync('nickName');
			avatarUrl = wx.getStorageSync('avatarUrl');
		} catch (e) {
			// Do something when catch error
		}
		if (nickName == '') {
			wx.showModal({
				title: '警告',
				content: '请先授权获取用户信息再进行留言',
			})
			return;
		}
		var that = this;
		wx.request({
			url: app.apiDomain + "index.php?c=health&a=addcomment",
			method: 'post',
			data: {
				'username': nickName,
				'icon': avatarUrl,
				'content': e.detail.value.text,
				'news_id': e.target.dataset.id
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded' // 默认值
			},
			success: function(res) {
				that.setData({
					common_list: res.data.data.list,
					common_total: res.data.data.total,
					inputTxt: '',
					input_on: ' '
				});
			}
		});

	},

	onShareAppMessage: function() {
		var nickName = '';
		var title = '';
		try {
			nickName = wx.getStorageSync('nickName');
			title = wx.getStorageSync('title');

		} catch (e) {
			// Do something when catch error
		}
		return {
			title: nickName + '推荐你阅读"' + title + '"'
		}
	},

})
